<template>
  <div class="user-layout">
    <el-container>
      <el-container>
        <el-aside width="200px">
          <el-menu :default-active="activeMenu" router class="el-menu-vertical">
            <el-menu-item index="/user/home">
              <el-icon><icon-menu /></el-icon>
              <span>首页</span>
            </el-menu-item>
            <el-menu-item index="/user/profile">
              <el-icon><icon-menu /></el-icon>
              <span>个人信息</span>
            </el-menu-item>
            <el-menu-item index="/user/medicine">
              <el-icon><icon-menu /></el-icon>
              <span>药品查询</span>
            </el-menu-item>
            <el-menu-item index="/user/cart">
              <el-icon><icon-menu /></el-icon>
              <span>购物车</span>
            </el-menu-item>
            <el-menu-item index="/user/order">
              <el-icon><icon-menu /></el-icon>
              <span>订单管理</span>
            </el-menu-item>
            <el-menu-item index="/user/address">
              <el-icon><icon-menu /></el-icon>
              <span>收货地址</span>
            </el-menu-item>
          </el-menu>
        </el-aside>

        <el-main>
          <!-- 子路由内容将在这里渲染 -->
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Menu as IconMenu } from '@element-plus/icons-vue'

const router = useRouter()
const route = useRoute()
const userInfo = ref({})

// 计算当前激活的菜单项
const activeMenu = computed(() => {
  return route.path
})

// 获取用户信息
onMounted(() => {
  const storedUserInfo = localStorage.getItem('userInfo')
  if (storedUserInfo) {
    userInfo.value = JSON.parse(storedUserInfo)
  } else {
    // 如果没有用户信息，重定向到登录页
    router.push('/login')
  }
})
</script>
